<?php
class D_images extends Model {

    function D_images()
    {
        parent::Model();
    }

    function get_items_count($categoryid)
    {
		$count = 0;

    	$sql = "SELECT count(*) as count FROM d_images where categoryid=$categoryid";
    	$query = $this->db->query($sql);
         foreach($query->result() as $row)
        {
        	$count = $row->count;
        	break;
        }   	
    	return $count;
    }
    

    function get_items($categoryid, $num=2000, $offset='0')
    {
		if($offset == '') $offset = 0;

    	$sql = "SELECT * FROM d_images where categoryid=$categoryid LIMIT $offset,$num";
    	$query = $this->db->query($sql);
    	
    	return $query->result();
    }
    
    
    function get_adpic_count($typeid, $positionid)
    {
		$count = 0;

    	$sql = "SELECT count(*) as count FROM d_ad_images where typeid=$typeid AND positionid=$positionid";
    	$query = $this->db->query($sql);
         foreach($query->result() as $row)
        {
        	$count = $row->count;
        	break;
        }   	
    	return $count;    	
    }    

    function get_adpics($typeid, $positionid, $num=2000, $offset='0')
    {
		if($offset == '') $offset = 0;

    	$sql = "SELECT a.* FROM d_ad_images a where a.typeid=$typeid AND a.positionid=$positionid LIMIT $offset,$num";
    	$query = $this->db->query($sql);
    	
    	return $query->result();
    }    
    
    function get_hotpic_count($shopid)
    {
		$count = 0;

    	$sql = "SELECT count(*) as count FROM d_hot_images where shopid=$shopid";
    	$query = $this->db->query($sql);
         foreach($query->result() as $row)
        {
        	$count = $row->count;
        	break;
        }   	
    	return $count;    	
    }    

    function get_hotpics($shopid, $num=2000, $offset='0')
    {
		if($offset == '') $offset = 0;

    	$sql = "SELECT a.*,b.name as shopname FROM d_hot_images a, conf_shop b where a.shopid=b.shopid AND a.shopid=$shopid LIMIT $offset,$num";
    	$query = $this->db->query($sql);
    	
    	return $query->result();
    }
        
        
        
    function get_image($imageid)
    {
    	$r = false;
    	
    	$sql = "SELECT * FROM d_images WHERE imageid=$imageid";
    	$query = $this->db->query($sql);
    	foreach($query->result() as $row)
    	{
    		$r = $row;
    		break;
    	}
    	return $r;
    }
    function remove($imageid)
    {
    	$this->db->query("DELETE FROM d_images WHERE imageid=$imageid");
    }
    
    
    
    function getcategory($categoryid)
    {
		$category = false;
		$query = $this->db->query("SELECT * FROM d_image_categories WHERE categoryid=$categoryid");
		foreach($query->result() as $r)
		{
			$category = $r;
			break;
		}
		return $category;    	
    }
}
?>
